<?php

namespace App\Http\Controllers\Guard\Article;

use App\Http\Controllers\Common\GuardController;
use App\Models\Article\ArticleClassify;
use App\Models\Article\ArticleInfo;
use EasyWeChat\Kernel\Messages\Article;
use Illuminate\Http\Request;


class ArticleClassifyController extends GuardController {

    public function lst(Request $request) {
        $conditions = $request->input();
        $conditions['orderBy']['col'] = 'id';
        $conditions['orderBy']['sort'] = 'asc';
        $conditions['pid'] = 0;
        $records = (new ArticleClassify())->getLst($conditions)->with('children')->get();
        $this->handleChildren($records);
        return responseSuccess($records->toArray());
    }

    public function add(Request $request) {

        try{
            $id = $request->input('id',0);
            $info = $request->input();
            ArticleClassify::updateOrCreate(compact('id'),$info);
            return responseSuccess();
        }catch(\Exception $e){
            $tip = $e->getFile().':'.$e->getLine().':'.$e->getMessage();
            return responseFail($tip);
        }
    }

    public function getRecord(Request $request) {

        return $this->getRecordByIds(ArticleClassify::class, $request->input('id','')); // TODO: Change the autogenerated stub
    }

    public function del(Request $request) {

        return $this->delRecords(ArticleClassify::class, $request->input('id',''));
    }

}
